package com.wuliang.generate.common.core.adapter.jpa.impl;


import com.wuliang.generate.common.core.adapter.jpa.EntityFieldTypeAdapter;
import com.wuliang.generate.common.core.basic.BasicEntity;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Predicate;
import java.util.List;

/**
 * 实体类集合字段适配器
 *
 * @author 邬魉
 */
public class CollectionFieldTypeAdapter implements EntityFieldTypeAdapter<List<Object>> {
    @Override
    @SuppressWarnings("unchecked")
    public Predicate toPredicate(Class<? extends BasicEntity> entity, CriteriaBuilder criteriaBuilder, String fieldName,
                                 List<Object> fieldValue, From<Object, List<Object>> from) {
        return criteriaBuilder.in(from.get(fieldName)).value(fieldValue);
    }
}
